package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.icid.store.business.delegate.TestcodeDelegate;
	import com.icid.store.event.GetTestcodeListEvent;
	import com.icid.store.event.SetTestcodeInfoEvent;
	import com.icid.store.model.TestcodeModelLocator;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;

	public class SetTestcodeInfoCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:TestcodeDelegate;
		private var setTestcodeInfoEvent:SetTestcodeInfoEvent;
		private var testcodeModel:TestcodeModelLocator = TestcodeModelLocator.getInstance();
		public function SetTestcodeInfoCommand()
		{
			super();
			delegate  = new TestcodeDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			setTestcodeInfoEvent = SetTestcodeInfoEvent(event);
			delegate.create(setTestcodeInfoEvent.simpleTestcode);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			switch(data.result.info)
			{
				case "success":
					Alert.show("Upload product testcode success!","SUCCESS");
					CairngormEventDispatcher.getInstance().dispatchEvent(new GetTestcodeListEvent());
					break;
				case "failure":
					Alert.show("Upload product testcode failure!","FAILURE");
					break;
				default:
					break;		
			}
		}
		
	}
}